import CONFIG from "./constant.js"
function Core(){
	
}


Core.prototype.createWebSocket=function(e,func,err){
	 return uni.connectSocket({
	   url: CONFIG.WS+e,
	   success:(cpl)=>{
		   if(typeof func=="function")func(cpl);
	   },
	   complete:(cpl)=>{},
	   fail:(fai)=>{
		   if(typeof err=="function")err(fai);
	   }
	 });
}
Core.prototype.onSocketOpen=function(func){
    uni.onSocketOpen((res)=>{if(typeof func=="function")func(res);});
}
Core.prototype.onSocketError=function(func){
	uni.onSocketError((res)=>{func(res);});
}
Core.prototype.sendSocketMessage=function(msg){
    uni.sendSocketMessage({ 
		data:msg,
		success:(cpl)=>{
			console.log("send_cpl========"+JSON.stringify(cpl))
		},
		fail:(fai)=>{
			console.log("send_fail========"+JSON.stringify(fai))
		}
	});
}
Core.prototype.onSocketMessage=function(func){
    uni.onSocketMessage((res)=>{if(typeof func=="function")func(res); });
}
Core.prototype.onSocketClose=function(func){
    uni.onSocketClose((res)=>{console.log("suc"); if(typeof func=="function")func(res);});
}
Core.prototype.closeSocket=function(){
    uni.closeSocket();
}

var wsUtil=new Core();
export default wsUtil